﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="NHOMA2_DVLH.WebForm1" %>

<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="float: right; width: 500px;font-size:14px">
        <h4>
            Trang này demo các kĩ thuật sau</h4>
        <ul>
            <li>AJAX : sử dụng AJAX Extension (ScriptManager, UpdatePanel) <a href="http://www.asp.net/ajax/tutorials/understanding-partial-page-updates-with-asp-net-ajax">link tham khảo</a>(khi xem chi tiết 1 tuyến xe hoặc delete sẽ ko load lại trang)</li>
            <li>Template Field
            <a href="http://www.asp.net/data-access/tutorials/using-templatefields-in-the-gridview-control-cs">link tham khảo Grid Template Field</a>
            <a href="http://www.asp.net/data-access/tutorials/using-templatefields-in-the-detailsview-control-cs">link tham khảo DetailView Template Field</a>
                <ul>
                    <li>Sửa lại header test thành tiếng việt</li>
                    <li>Custom control : sử dụng combobox cho chọn khi update, insert Trạm (show thông tin trạm of tuyến)</li>                    
                    <li>Delete có confirm (chức năng xóa tuyến xe)</li>
                    <li>Validation control : chèn vào tương tự như custom control. Dùng để kiểm tra các lỗi cú pháp
                        khi update, insert (chức năng sửa thông tin tuyến xe )</li>
                        <a href="http://www.asp.net/data-access/tutorials/adding-validation-controls-to-the-editing-and-inserting-interfaces-cs">link tham khảo</a>
                </ul>
            </li>
            <li>Update, Delete, Insert Event Handling : sử dụng để xử lý các lỗi logic (chức năng xóa tuyến xe còn ràng buộc khóa ngoại) 
            <a href="http://www.asp.net/data-access/tutorials/handling-bll-and-dal-level-exceptions-in-an-asp-net-page-cs">link tham khảo</a></li>
        </ul>
    </div>
    <div>
        <h2>
            Demo</h2>
        <h2>
            Chi tiết tuyến xe</h2>
        <br />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" EnableViewState="True">
            <ContentTemplate>
                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4"
                    DataKeyNames="MaTuyenXe" DataSourceID="TuyenXeDetailDataSource" ForeColor="#333333"
                    GridLines="None" Height="50px" Width="382px">
                    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
                    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                    <FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
                    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                    <Fields>
                        <asp:BoundField DataField="MaTuyenXe" HeaderText="Mã Tuyến Xe" InsertVisible="False"
                            ReadOnly="True" SortExpression="MaTuyenXe" />
                        <asp:TemplateField HeaderText="Tổng Thời Gian" SortExpression="TongThoiGian">
                            <EditItemTemplate>
                                <asp:TextBox ID="txtDetailTongThoiGian" runat="server" Text='<%# Bind("TongThoiGian") %>'></asp:TextBox>
                                <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtDetailTongThoiGian"
                                    ErrorMessage="phải là một số nguyên 1-100" MaximumValue="100" MinimumValue="1"
                                    Type="Integer"></asp:RangeValidator>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TongThoiGian") %>'></asp:TextBox>
                                <asp:RangeValidator ID="RangeValidator1" runat="server" 
                                    ControlToValidate="TextBox1" ErrorMessage="phải là một số nguyên 1-100" 
                                    MaximumValue="100" MinimumValue="1" Type="Integer"></asp:RangeValidator>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("TongThoiGian") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Khung Thời Gian" SortExpression="KhungThoiGian">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("KhungThoiGian") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("KhungThoiGian") %>'></asp:TextBox>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("KhungThoiGian") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Trạm Xuất Phát">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="TramDataSource"
                                    DataTextField="TenTram" DataValueField="MaTram" SelectedValue='<%# Bind("MaTramXuatPhat") %>'>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="TramDataSource"
                                    DataTextField="TenTram" DataValueField="MaTram" SelectedValue='<%# Bind("MaTramXuatPhat") %>'>
                                </asp:DropDownList>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="TramDataSource"
                                    DataTextField="TenTram" DataValueField="MaTram" Enabled="False" SelectedValue='<%# Bind("MaTramXuatPhat") %>'>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Trạm Đích" SortExpression="MaTramDich">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="TramDataSource"
                                    DataTextField="TenTram" DataValueField="MaTram" SelectedValue='<%# Bind("MaTramDich") %>'>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="TramDataSource"
                                    DataTextField="TenTram" DataValueField="MaTram" SelectedValue='<%# Bind("MaTramDich") %>'>
                                </asp:DropDownList>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="TramDataSource"
                                    DataTextField="TenTram" DataValueField="MaTram" Enabled="False" SelectedValue='<%# Bind("MaTramDich") %>'>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False">
                            <EditItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                    Text="Cập nhật"></asp:LinkButton>
                                &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                    Text="Hủy"></asp:LinkButton>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert"
                                    Text="Thêm mới"></asp:LinkButton>
                                &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                    Text="Hủy"></asp:LinkButton>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                    Text="Sửa thông tin"></asp:LinkButton>
                                &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="New"
                                    Text="Thêm mới"></asp:LinkButton>
                                &nbsp;
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Fields>
                    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:DetailsView>
                </p>
                <h2>
                    Danh sách các tuyến xe</h2>
                <p>
                    <asp:Label ID="lblErrorDelete" runat="server" Font-Bold="True" ForeColor="Red" 
                        Visible="False"></asp:Label>
                </p>
                <asp:GridView ID="gvDanhSachTuyenXe" runat="server" AutoGenerateColumns="False" DataKeyNames="MaTuyenXe"
                    DataSourceID="TuyenXeDataSource" AllowPaging="True" CellPadding="4" ForeColor="#333333"
                    GridLines="None" PageSize="5" onrowdeleted="gvDanhSachTuyenXe_RowDeleted">
                    <RowStyle BackColor="#EFF3FB" />
                    <Columns>
                        <asp:BoundField DataField="MaTuyenXe" HeaderText="Mã Tuyến" InsertVisible="False"
                            ReadOnly="True" SortExpression="MaTuyenXe" />
                        <asp:BoundField DataField="TongThoiGian" HeaderText="Tổng Thời Gian" SortExpression="TongThoiGian" />
                        <asp:BoundField DataField="KhungThoiGian" HeaderText="Khung Thời Gian" SortExpression="KhungThoiGian" />
                        <asp:TemplateField HeaderText="Trạm Xuất Phát" SortExpression="MaTramXuatPhat">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MaTramXuatPhat") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("MaTramXuatPhat") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="MaTramDich" HeaderText="Trạm Đích" SortExpression="MaTramDich" />
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select"
                                    Text="Chi tiết"></asp:LinkButton>
                                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
                                    Text="Xóa" OnClientClick="return confirm('Bạn chắc chắn muốn xóa tuyến xe này ? ');"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#2461BF" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:ObjectDataSource ID="TuyenXeDetailDataSource" runat="server" DeleteMethod="DeleteTuyenXe"
            InsertMethod="InsertTuyenXe" SelectMethod="GetTuyenXeByMaTuyenXe" TypeName="NHOMA2_DVLH.App_Lib.BLL.TuyenXeBLL"
            UpdateMethod="UpdateTuyenXe">
            <DeleteParameters>
                <asp:Parameter Name="maTuyenXe" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="tongThoiGian" Type="Int32" />
                <asp:Parameter Name="khungThoiGian" Type="String" />
                <asp:Parameter Name="maTramXuatPhat" Type="Int32" />
                <asp:Parameter Name="maTramDich" Type="Int32" />
                <asp:Parameter Name="maTuyenXe" Type="Int32" />
            </UpdateParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="gvDanhSachTuyenXe" Name="maTuyenXe" PropertyName="SelectedValue"
                    Type="Int32" DefaultValue="1000" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="tongThoiGian" Type="Int32" />
                <asp:Parameter Name="khungThoiGian" Type="String" />
                <asp:Parameter Name="maTramXuatPhat" Type="Int32" />
                <asp:Parameter Name="maTramDich" Type="Int32" />
            </InsertParameters>
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="TramDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetTram" TypeName="NHOMA2_DVLH.App_Lib.BLL.TramBLL"></asp:ObjectDataSource>
        <asp:ObjectDataSource ID="TuyenXeDataSource" runat="server" DeleteMethod="DeleteTuyenXe"
            SelectMethod="GetTuyenXe" TypeName="NHOMA2_DVLH.App_Lib.BLL.TuyenXeBLL"
            OldValuesParameterFormatString="original_{0}" InsertMethod="InsertTuyenXe" 
            UpdateMethod="UpdateTuyenXe">
            <DeleteParameters>
                <asp:Parameter Name="maTuyenXe" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="tongThoiGian" Type="Int32" />
                <asp:Parameter Name="khungThoiGian" Type="String" />
                <asp:Parameter Name="maTramXuatPhat" Type="Int32" />
                <asp:Parameter Name="maTramDich" Type="Int32" />
                <asp:Parameter Name="maTuyenXe" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="tongThoiGian" Type="Int32" />
                <asp:Parameter Name="khungThoiGian" Type="String" />
                <asp:Parameter Name="maTramXuatPhat" Type="Int32" />
                <asp:Parameter Name="maTramDich" Type="Int32" />
            </InsertParameters>
        </asp:ObjectDataSource>
    </div>
    </form>
</body>
</html>
